home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / k3bdevice.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-05-27  |  25.4 KB  |  837 lines

  1. /*
  2.  *
  3.  * $Id: k3bdevice.h 679274 2007-06-23 13:23:58Z trueg $
  4.  * Copyright (C) 2003-2007 Sebastian Trueg <trueg@k3b.org>
  5.  *
  6.  * This file is part of the K3b project.
  7.  * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
  8.  *
  9.  * This program is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2 of the License, or
  12.  * (at your option) any later version.
  13.  * See the file "COPYING" for the exact licensing terms.
  14.  */
  15.  
  16.  
  17. #ifndef K3BDEVICE_H
  18. #define K3BDEVICE_H
  19.  
  20. #include <qstringlist.h>
  21. #include <qvaluelist.h>
  22. #include <qglobal.h>
  23.  
  24. #include <k3bdevicetypes.h>
  25. #include <k3bdiskinfo.h>
  26. #include <k3bcdtext.h>
  27. #include <k3bmsf.h>
  28. #include <k3bdevice_export.h>
  29.  
  30. #ifdef Q_OS_FREEBSD
  31. struct cam_device;
  32. #endif
  33.  
  34. namespace K3bDevice
  35. {
  36.   class Toc;
  37.  
  38.   /**
  39.    * \brief The main class representing a device.
  40.    *
  41.    * Devices are constructed by the DeviceManager.
  42.    *
  43.    * All methods except for open and close in Device are thread-safe which basicly means that
  44.    * no two commands are sent to the device at the same time.
  45.    */
  46.   // FIXME: all methods are const which makes no sense at all!
  47.   class LIBK3BDEVICE_EXPORT Device
  48.     {
  49.     public:
  50. #ifdef Q_OS_FREEBSD
  51.       typedef struct cam_device* Handle;
  52. #else
  53.     // file descriptor
  54.       typedef int Handle;
  55. #endif
  56.  
  57.       /**
  58.        * The available cdrdao drivers
  59.        * \deprecated This will be moved to libk3b
  60.        */
  61.       static const char* cdrdao_drivers[];
  62.  
  63.       // FIXME: make this protected
  64.       ~Device();
  65.  
  66.       /**
  67.        * The interface type.
  68.        *
  69.        * \return K3bDevice::SCSI or K3bDevice::IDE.
  70.        */
  71.       Interface interfaceType() const;
  72.  
  73.       /**
  74.        * \deprecated use readCapabilities() and writeCapabilities()
  75.        * The device type.
  76.        *
  77.        * @return A bitwise or of K3bDevice::DeviceType.
  78.        */
  79.       int type() const;
  80.  
  81.       /**
  82.        * The mediatypes this device is able to read.
  83.        *
  84.        * \return A bitwise or of K3bDevice::MediaType
  85.        */
  86.       int readCapabilities() const;
  87.  
  88.       /**
  89.        * The media types this device is able to write.
  90.        *
  91.        * \return A bitwise or of K3bDevice::MediaType
  92.        */      
  93.       int writeCapabilities() const;
  94.  
  95.       /**
  96.        * \return Vendor string as reported by the device's firmware.
  97.        */
  98.       const QString& vendor() const { return m_vendor; }
  99.  
  100.       /**
  101.        * \return Description string as reported by the device's firmware.
  102.        */
  103.       const QString& description() const { return m_description; }
  104.  
  105.       /**
  106.        * \return Version string as reported by the device's firmware.
  107.        */
  108.       const QString& version() const { return m_version; }
  109.  
  110.       /**
  111.        * Shortcut for \code writesCd() || writesDvd() \endcode
  112.        *
  113.        * \return true if the device is able to burn media.
  114.        */
  115.       bool burner() const;
  116.  
  117.       /**
  118.        * Shortcut for \code type() & DEVICE_CD_R \endcode
  119.        *
  120.        * \return true if the device is able to burn CD-R media.
  121.        */
  122.       bool writesCd() const;
  123.  
  124.       /**
  125.        * Shortcut for \code type() & DEVICE_CD_RW \endcode
  126.        *
  127.        * \return true if the device is able to burn CD-RW media.
  128.        */
  129.       bool writesCdrw() const;
  130.  
  131.       /**
  132.        * Shortcut for \code writesDvdMinus() || writesDvdPlus() \endcode
  133.        *
  134.        * \return true if the device is able to burn DVD media.
  135.        */
  136.       bool writesDvd() const;
  137.  
  138.  
  139.       /**
  140.        * Shortcut for \code type() & (DEVICE_DVD_PLUS_R|DEVICE_DVD_PLUS_RW) \endcode
  141.        *
  142.        * \return true if the device is able to burn DVD+R or DVD+RW media.
  143.        */
  144.       bool writesDvdPlus() const;
  145.  
  146.       /**
  147.        * Shortcut for \code type() & (DEVICE_DVD_R|DEVICE_DVD_RW) \endcode
  148.        *
  149.        * \return true if the device is able to burn DVD-R or DVD-RW media.
  150.        */
  151.       bool writesDvdMinus() const;
  152.  
  153.       /**
  154.        * Shortcut for \code type() & DEVICE_DVD_ROM \endcode
  155.        *
  156.        * \return true if the device is able to read DVD media.
  157.        */
  158.       bool readsDvd() const;
  159.  
  160.       /**
  161.        * @deprecated Use burnfree()
  162.        */
  163.       bool burnproof() const;
  164.  
  165.       /**
  166.        * @return true is the device is a writer and supports buffer underrun free recording (BURNFREE)
  167.        */
  168.       bool burnfree() const;
  169.  
  170.       /**
  171.        * Shortcut for \code writingModes() & WRITINGMODE_SAO \endcode
  172.        *
  173.        * \deprecated use supportsWritingMode()
  174.        */
  175.       bool dao() const;
  176.  
  177.       /**
  178.        * Check if the device supports a certain writing mode.
  179.        *
  180.        * \return true if the device supports the requested writing mode or false otherwise.
  181.        */
  182.       bool supportsWritingMode( WritingMode mode ) const { return (m_writeModes & mode); }
  183.  
  184.       /**
  185.        * Shortcut for 
  186.        * \code
  187.        *  writingModes() & (WRITINGMODE_RAW|WRITINGMODE_RAW_R16|WRITINGMODE_RAW_R96P|WRITINGMODE_RAW_R96R)
  188.        * \endcode
  189.        */
  190.       bool supportsRawWriting() const;
  191.  
  192.       /**
  193.        * @return true if the device is a DVD-R(W) writer which supports test writing.
  194.        */
  195.       bool dvdMinusTestwrite() const { return m_dvdMinusTestwrite; }
  196.  
  197.       int maxReadSpeed() const { return m_maxReadSpeed; }
  198.       int currentWriteSpeed() const { return m_currentWriteSpeed; }
  199.  
  200.       /**
  201.        * Size of the device's internal writing buffer.
  202.        *
  203.        * \return The size of the buffer in KB.
  204.        */
  205.       int bufferSize() const { return m_bufferSize; }
  206.  
  207.       /**
  208.        * @return the corresponding device name.
  209.        */
  210.       const QString& devicename() const;
  211.  
  212.       /**
  213.        * for SCSI devices this should be something like /dev/scd0 or /dev/sr0
  214.        * for IDE device this should be something like /dev/hdb1
  215.        */
  216.       const QString& blockDeviceName() const { return m_blockDevice; }
  217.  
  218.       /**
  219.        * This is only valid for SCSI devices. Without devfs it's something
  220.        * like /dev/sg0. Otherwise something like /dev/scsi/host0/bus0/target0/lun0/generic.
  221.        *
  222.        * This is not needed in K3b at all. But cdrecord and cdrdao use the sg devices and
  223.        * we need it to fixup it's permissions in K3bSetup.
  224.        */
  225.       const QString& genericDevice() const { return m_genericDevice; }
  226.  
  227.       /**
  228.        * \return All device nodes for this drive.
  229.        */
  230.       const QStringList& deviceNodes() const;
  231.  
  232.       /**
  233.        * \see K3bDevice::Device::deviceNodes()
  234.        */
  235.       void addDeviceNode( const QString& );
  236.  
  237.       /**
  238.        * Makes only sense to use with scsi devices
  239.        * @return a string for use with the cdrtools
  240.        * @deprecated
  241.        */
  242.       QString busTargetLun() const;
  243.  
  244.       int scsiBus() const { return m_bus; }
  245.       int scsiId() const { return m_target; }
  246.       int scsiLun() const { return m_lun; }
  247.  
  248.       int maxWriteSpeed() const { return m_maxWriteSpeed; }
  249.  
  250.       /**
  251.        * \deprecated the cdrdao driver has no place in this library. It will be removed.
  252.        */
  253.       const QString& cdrdaoDriver() const { return m_cdrdaoDriver; }
  254.  
  255.       /**
  256.        * returns: 0 auto (no cdrdao-driver selected)
  257.        *          1 yes
  258.        *          2 no
  259.        *
  260.        * \deprecated cdrdao specific stuff has no place in this library. It will be removed.
  261.        */
  262.       int cdTextCapable() const;
  263.  
  264.       /**
  265.        * internal K3b value.
  266.        * \deprecated This should not be handled here.
  267.        */
  268.       void setCurrentWriteSpeed( int s ) { m_currentWriteSpeed = s; }
  269.  
  270.       /**
  271.        * Use this if the speed was not detected correctly.
  272.        */
  273.       void setMaxReadSpeed( int s ) { m_maxReadSpeed = s; }
  274.  
  275.       /**
  276.        * Use this if the speed was not detected correctly.
  277.        */
  278.       void setMaxWriteSpeed( int s ) { m_maxWriteSpeed = s; }
  279.  
  280.       /**
  281.        * Use this if cdrdao is not able to autodetect the nessessary driver.
  282.        * \deprecated the cdrdao driver has no place in this library. It will be removed.
  283.        */
  284.       void setCdrdaoDriver( const QString& d ) { m_cdrdaoDriver = d; }
  285.  
  286.       /**
  287.        * Only used if the cdrdao-driver is NOT set to "auto".
  288.        * In that case it must be manually set because there
  289.        * is no way to autosense the cd-text capability.
  290.        *
  291.        * \deprecated the cdrdao driver has no place in this library. It will be removed.
  292.        */
  293.       void setCdTextCapability( bool );
  294.  
  295.       /**
  296.        * checks if unit is ready (medium inserted and ready for command)
  297.        *
  298.        * Refers to the MMC command: TEST UNIT READY
  299.        */
  300.       bool testUnitReady() const;
  301.  
  302.       /**
  303.        * checks if disk is empty, returns @p K3bDevice::State
  304.        */
  305.       int isEmpty() const;
  306.  
  307.       /**
  308.        * @return true if inserted media is rewritable.
  309.        */
  310.       bool rewritable() const;
  311.  
  312.       /**
  313.        * Check if the inserted media is a DVD.
  314.        *
  315.        * \return true if the inserted media is a DVD.
  316.        */
  317.       bool isDVD() const;
  318.  
  319.       /**
  320.        * @return The number of sessions on the media.
  321.        */
  322.       int numSessions() const;
  323.  
  324.       /**
  325.        * @return The toc of the media or an empty (invalid) K3bDevice::Toc if 
  326.        *         no or an empty media is inserted.
  327.        */
  328.       Toc readToc() const;
  329.  
  330.       /**
  331.        * Append ISRC and MCN to the TOC if found
  332.        * This has been moved to a separate method since it can take a very long time
  333.        * to scan for all ISRCs.
  334.        */
  335.       void readIsrcMcn( Toc& toc ) const;
  336.  
  337.       /**
  338.        * Read the CD-TEXT of an audio or mixed-mode CD.
  339.        *
  340.        * \return A CdText object filled with the CD-TEXT values or an empty one in case of
  341.        *         pure data media or if the CD does not contain CD-TEXT.
  342.        */
  343.       CdText readCdText() const;
  344.  
  345.       /**
  346.        * @return The K3bDevice::Track::DataMode of the track.
  347.        * @see K3bDevice::Track
  348.        */
  349.       int getTrackDataMode( const Track& track ) const;
  350.  
  351.       /**
  352.        * @return the mode of a data track. K3bDevice::Track::MODE1, K3bDevice::Track::MODE2, 
  353.        *         K3bDevice::Track::XA_FORM1, or K3bDevice::Track::XA_FORM2.
  354.        */
  355.       int getDataMode( const K3b::Msf& sector ) const;
  356.  
  357.       /**
  358.        * block or unblock the drive's tray
  359.        * \return true on success and false on error.
  360.        * \see eject()
  361.        */
  362.       bool block( bool ) const;
  363.  
  364.       /**
  365.        * Eject the media.
  366.        * \return true on success and false on error.
  367.        * \see load()
  368.        */
  369.       bool eject() const;
  370.  
  371.       /**
  372.        * Load the media.
  373.        * @return true on success and false on error.
  374.        */
  375.       bool load() const;
  376.  
  377.       /**
  378.        * Enable or disable auto-ejecting. For now this is a no-op on non-Linux systems.
  379.        * \param enabled if true auto-ejecting will be enabled, otherwise disabled.
  380.        * \return true if the operation was successful, false otherwise
  381.        */
  382.       bool setAutoEjectEnabled( bool enabled ) const;
  383.  
  384.       /**
  385.        * The supported writing modes.
  386.        *
  387.        * \return A bitwise or of K3bDevice::WritingMode or 0 in case of a read-only device.
  388.        */
  389.       int writingModes() const { return m_writeModes; }
  390.  
  391.       bool readSectorsRaw(unsigned char *buf, int start, int count) const;
  392.  
  393.       /**
  394.        * Get a list of supported profiles. See enumeration MediaType.
  395.        */
  396.       int supportedProfiles() const;
  397.  
  398.       /**
  399.        * Tries to get the current profile from the drive.
  400.        * @returns -1 on error (command failed or unknown profile)
  401.        *          MediaType otherwise (MEDIA_NONE means: no current profile)
  402.        */
  403.       int currentProfile() const;
  404.  
  405.       /**
  406.        * Check if a certain feature is current.
  407.        * \see k3bdevicetypes.h for feature constants.
  408.        * \return 1 if the feature is current, 0 if not, -1 on error
  409.        */
  410.       int featureCurrent( unsigned int feature ) const;
  411.  
  412.       /**
  413.        * This is the method to use!
  414.        */
  415.       DiskInfo diskInfo() const;
  416.  
  417.       /**
  418.        * Refers to MMC command READ CAPACITY
  419.        */
  420.       bool readCapacity( K3b::Msf& ) const;
  421.  
  422.       /**
  423.        * Refers to MMC command READ FORMAT CAPACITY
  424.        *
  425.        * @param wantedFormat The requested format type.
  426.        * @param result If true is returned this contains the requested value.
  427.        * @param currentMax If not 0 this will be filled with the Current/Maximum Descriptor value.
  428.        * @param currentMax If not 0 this will be filled with the Current/Maximum Format Type.
  429.        */
  430.       bool readFormatCapacity( int wantedFormat, K3b::Msf& result,
  431.                    K3b::Msf* currentMax = 0, int* currentMaxFormat = 0 ) const;
  432.  
  433.       /**
  434.        * Determine the type of the currently mounted medium
  435.        *
  436.        * @returns K3bDevice::MediaType
  437.        */
  438.       int mediaType() const;
  439.  
  440.       /**
  441.        * Returnes the list of supported writing speeds as reported by
  442.        * mode page 2Ah.
  443.        *
  444.        * This only works with MMC3 compliant drives.
  445.        */
  446.       QValueList<int> determineSupportedWriteSpeeds() const;
  447.  
  448.       /**
  449.        * @returnes the speed in kb/s or 0 on failure.
  450.        */
  451.       int determineMaximalWriteSpeed() const;
  452.  
  453.       /**
  454.        * Open the device for access via a file descriptor.
  455.        * @return true on success or if the device is already open.
  456.        * @see close()
  457.        *
  458.        * Be aware that this method is not thread-safe.
  459.        */
  460.       bool open( bool write = false ) const;
  461.  
  462.       /**
  463.        * Close the files descriptor.
  464.        * @see open()
  465.        *
  466.        * Be aware that this method is not thread-safe.
  467.        */
  468.       void close() const;
  469.  
  470.       /**
  471.        * @return true if the device was successfully opened via @p open()
  472.        */
  473.       bool isOpen() const;
  474.  
  475.       /**
  476.        * fd on linux, cam on bsd
  477.        */
  478.       Handle handle() const;
  479.  
  480.       /**
  481.        * \return \li -1 on error (no DVD)
  482.        *         \li 1 (CSS/CPPM)
  483.        *         \li 2 (CPRM) if scrambled
  484.        *         \li 0 otherwise
  485.        */
  486.       int copyrightProtectionSystemType() const;
  487.  
  488.       // MMC commands
  489.  
  490.       /**
  491.        * SET SPEED command
  492.        *
  493.        * @param readingSpeed The preferred reading speed (0x0000-0xFFFE). 0xFFFF requests
  494.        *                     fot the logical unit to select the optimal speed.
  495.        * @param writingSpeed The preferred writing speed (0x0000-0xFFFE). 0xFFFF requests
  496.        *                     fot the logical unit to select the optimal speed.
  497.        * @param cav Is the speed pure CAV?
  498.        */
  499.       bool setSpeed( unsigned int readingSpeed,
  500.              unsigned int writingSpeed,
  501.              bool cav = false ) const;
  502.  
  503.       /**
  504.        * if true is returned dataLen specifies the actual length of *data which needs to be
  505.        * deleted after using.
  506.        */
  507.       bool readDiscInformation( unsigned char** data, unsigned int& dataLen ) const;
  508.  
  509.       /**
  510.        * @param pf If false all fields in the descriptor data is vendor specific. Default should be true.
  511.        */
  512.       bool modeSelect( unsigned char* page, unsigned int pageLen, bool pf, bool sp ) const;
  513.  
  514.       /**
  515.        * if true is returned pageLen specifies the actual length of *pageData which needs to be
  516.        * deleted after using.
  517.        */
  518.       bool modeSense( unsigned char** pageData, unsigned int& pageLen, int page ) const;
  519.  
  520.       /**
  521.        * if true is returned dataLen specifies the actual length of *data which needs to be
  522.        * deleted after using.
  523.        */
  524.       bool readTocPmaAtip( unsigned char** data, unsigned int& dataLen, int format, bool msf, int track ) const;
  525.  
  526.       /**
  527.        * @param type specifies what value means:
  528.        *        \li 00b - value refers to a logical block address
  529.        *        \li 01b - value refers to a track number where 0 will treat the lead-in as if it
  530.        *                  were a logical track and ffh will read the invisible or incomplete track.
  531.        *        \li 10b - value refers to a session number
  532.        *
  533.        */
  534.       bool readTrackInformation( unsigned char** data, unsigned int& dataLen, int type, int value ) const;
  535.  
  536.       /**
  537.        * if true is returned dataLen specifies the actual length of *data which needs to be
  538.        * deleted after using.
  539.        */
  540.       bool readDiscStructure( unsigned char** data, unsigned int& dataLen, 
  541.                   unsigned int mediaType = 0x0,
  542.                   unsigned int format = 0x0,
  543.                   unsigned int layer = 0x0,
  544.                   unsigned long adress = 0,
  545.                   unsigned int agid = 0x0 ) const;
  546.  
  547.       /**
  548.        * In MMC5 readDvdStructure was renamed to readDiscStructure. This method does the same
  549.        * like the above.
  550.        */
  551.       bool readDvdStructure( unsigned char** data, unsigned int& dataLen, 
  552.                  unsigned int format = 0x0,
  553.                  unsigned int layer = 0x0,
  554.                  unsigned long adress = 0,
  555.                  unsigned int agid = 0x0 ) const;
  556.  
  557.       /**
  558.        * if true is returned dataLen specifies the actual length of *data which needs to be
  559.        * deleted after using.
  560.        */
  561.       bool mechanismStatus( unsigned char** data, unsigned int& dataLen ) const;
  562.  
  563.       /**
  564.        * Read a single feature.
  565.        * data will be filled with the feature header and the descriptor
  566.        */
  567.       bool getFeature( unsigned char** data, unsigned int& dataLen, unsigned int feature ) const;
  568.  
  569.  
  570.       /**
  571.        * if true is returned dataLen specifies the actual length of *data which needs to be
  572.        * deleted after using.
  573.        */
  574.       bool getPerformance( unsigned char** data, unsigned int& dataLen,
  575.                unsigned int type,
  576.                unsigned int dataType,
  577.                unsigned int lba = 0 ) const;
  578.  
  579.       /**
  580.        * @param sectorType: \li 000b - all types
  581.        *                    \li 001b - CD-DA
  582.        *                    \li 010b - Mode 1
  583.        *                    \li 011b - Mode 2 formless
  584.        *                    \li 100b - Mode 2 form 1
  585.        *                    \li 101b - Mode 2 form 2
  586.        *
  587.        * @param startAdress Lba 0 is mapped to msf 00:00:00 so this method uses
  588.        *                    startAdress+150 as the starting msf.
  589.        *
  590.        * @param endAdress This is the ending address which is NOT included in the read operation.
  591.        *                  Lba 0 is mapped to msf 00:00:00 so this method uses
  592.        *                  endAdress+150 as the ending msf.
  593.        *
  594.        * @param c2:         \li 00b  - No error info
  595.        *                    \li 01b  - 294 bytes, one bit for every byte of the 2352 bytes
  596.        *                    \li 10b  - 296 bytes, xor of all c2 bits, zero pad bit, 294 c2 bits
  597.        *
  598.        * @param subChannel: \li 000b - No Sub-channel data
  599.        *                    \li 001b - RAW P-W Sub-channel (96 bytes)
  600.        *                    \li 010b - Formatted Q Sub-channel (16 bytes)
  601.        *                    \li 100b - Corrected and de-interleaved R-W Sub-channel (96 bytes)
  602.        */
  603.       bool readCdMsf( unsigned char* data,
  604.               unsigned int dataLen,
  605.               int sectorType,
  606.               bool dap,
  607.               const K3b::Msf& startAdress,
  608.               const K3b::Msf& endAdress,
  609.               bool sync,
  610.               bool header,
  611.               bool subHeader,
  612.               bool userData,
  613.               bool edcEcc,
  614.               int c2,
  615.               int subChannel ) const;
  616.  
  617.       /**
  618.        * @param sectorType: \li 000b - all types
  619.        *                    \li 001b - CD-DA
  620.        *                    \li 010b - Mode 1
  621.        *                    \li 011b - Mode 2 formless
  622.        *                    \li 100b - Mode 2 form 1
  623.        *                    \li 101b - Mode 2 form 2
  624.        *
  625.        * @param c2:         \li 00b  - No error info
  626.        *                    \li 01b  - 294 bytes, one bit for every byte of the 2352 bytes
  627.        *                    \li 10b  - 296 bytes, xor of all c2 bits, zero pad bit, 294 c2 bits
  628.        *
  629.        * @param subChannel: \li 000b - No Sub-channel data
  630.        *                    \li 001b - RAW P-W Sub-channel (96 bytes)
  631.        *                    \li 010b - Formatted Q Sub-channel (16 bytes)
  632.        *                    \li 100b - Corrected and de-interleaved R-W Sub-channel (96 bytes)
  633.        */
  634.       bool readCd( unsigned char* data,
  635.            unsigned int dataLen,
  636.            int sectorType,
  637.            bool dap,
  638.            unsigned long startAdress,
  639.            unsigned long length,
  640.            bool sync,
  641.            bool header,
  642.            bool subHeader,
  643.            bool userData,
  644.            bool edcEcc,
  645.            int c2,
  646.            int subChannel ) const;
  647.  
  648.       bool read10( unsigned char* data,
  649.            unsigned int dataLen,
  650.            unsigned long startAdress,
  651.            unsigned int length,
  652.            bool fua = false ) const;
  653.  
  654.       bool read12( unsigned char* data,
  655.            unsigned int dataLen,
  656.            unsigned long startAdress,
  657.            unsigned long length,
  658.            bool streaming = false,
  659.            bool fua = false ) const;
  660.  
  661.       /**
  662.        * @param subchannelParam: 01h - CD current position
  663.        *                         02h - Media Catalog number (UPC/bar code)
  664.        *                         03h - ISRC
  665.        * @param trackNumber only valid if subchannelParam == 03h
  666.        */
  667.       bool readSubChannel( unsigned char** data,
  668.                unsigned int& dataLen,
  669.                unsigned int subchannelParam,
  670.                unsigned int trackNumber ) const;
  671.  
  672.       bool readIsrc( unsigned int track, QCString& isrc ) const;
  673.  
  674.       bool readMcn( QCString& mcn ) const;
  675.  
  676.       /**
  677.        * MMC command Read Buffer Capacity
  678.        *
  679.        * \return \see K3bScsiCommand::transport()
  680.        */
  681.       int readBufferCapacity( long long& bufferLength, long long& bufferAvail ) const;
  682.  
  683.       /**
  684.        * @returns the index number on success
  685.        *          -1 on general error
  686.        *          and -2 if there is no index info in that frame
  687.        */
  688.       int getIndex( unsigned long lba ) const;
  689.  
  690.       bool searchIndex0( unsigned long startSec, unsigned long endSec, long& pregapStart ) const;
  691.  
  692.       /**
  693.        * For now this just searches index 0 for all tracks and sets
  694.        * the value in the tracks.
  695.        * In the future this should scan for all indices.
  696.        */
  697.       bool indexScan( K3bDevice::Toc& toc ) const;
  698.  
  699.       /**
  700.        * Seek to the specified sector.
  701.        */
  702.       bool seek( unsigned long lba ) const;
  703.  
  704.       bool getNextWritableAdress( unsigned int& lastSessionStart, unsigned int& nextWritableAdress ) const;
  705.  
  706.       /**
  707.        * Retrieve the next writable address from the currently mounted writable medium.
  708.        * \return The next writable address if the medium is empty or appendable or -1
  709.        * if an error occured.
  710.        */
  711.       int nextWritableAddress() const;
  712.  
  713.       /**
  714.        * Locks the device for usage. This means that no MMC command can be performed
  715.        * until usageUnlock is called.
  716.        *
  717.        * Locking a device is useful when an external application or library is called
  718.        * that opens the device itself.
  719.        *
  720.        * \sa usageUnlock
  721.        */
  722.       void usageLock() const;
  723.  
  724.       /**
  725.        * Unlock the device after a call to usageLock.
  726.        */
  727.       void usageUnlock() const;
  728.  
  729.       /**
  730.        * Thread-safe ioctl call for this device for Linux and Net-BSD systems.
  731.        * Be aware that so far this does not include opening the device
  732.        */
  733. //      int ioctl( int request, ... ) const;
  734.  
  735.     protected:
  736.       bool furtherInit();
  737.  
  738. #ifdef Q_OS_LINUX
  739.       /**
  740.        * Fallback method that uses the evil cdrom.h stuff
  741.        */
  742.       bool readTocLinux( Toc& ) const;
  743. #endif
  744.  
  745.       /**
  746.        * The preferred toc reading method for all CDs. Also reads session info.
  747.        * undefined for DVDs.
  748.        */
  749.       bool readRawToc( Toc& ) const;
  750.       bool readFormattedToc( Toc&, int mediaType ) const;
  751.  
  752.       /**
  753.        * Fixes the last block on CD-Extra disks. This is needed if the readRawToc failed since
  754.        * in that case the first sector of the last session's first track is used as the previous
  755.        * session's last track's last sector which is wrong. There is a 11400 block session lead-in
  756.        * between them. This method fixes this only for the last session and only on linux.
  757.        */
  758.       bool fixupToc( Toc& ) const;
  759.  
  760.     private:
  761.       /**
  762.        * A Device can only be constructed the the DeviceManager.
  763.        */
  764.       Device( const QString& devname );
  765.  
  766.       /**
  767.        * Determines the device's capabilities. This needs to be called once before
  768.        * using the device.
  769.        *
  770.        * Should only be used by the DeviceManager.
  771.        *
  772.        * @param checkWritingModes if true the CD writing modes will be checked using 
  773.        *                          MMC_MODE_SELECT.
  774.        */
  775.       bool init( bool checkWritingModes = true );
  776.  
  777.       void searchIndexTransitions( long start, long end, K3bDevice::Track& track ) const;
  778.       void checkWritingModes();
  779.       void checkFeatures();
  780.       void checkForJustLink();
  781.       void checkFor2AFeatures();
  782.       void checkForAncientWriters();
  783.  
  784.       /**
  785.        * Internal method which checks if the raw toc data has bcd values or hex.
  786.        * @return 0 if hex, 1 if bcd, -1 if none
  787.        */
  788.       int rawTocDataWithBcdValues( unsigned char* data, unsigned int dataLen ) const;
  789.  
  790.       bool getSupportedWriteSpeedsVia2A( QValueList<int>& list, bool dvd ) const;
  791.       bool getSupportedWriteSpeedsViaGP( QValueList<int>& list, bool dvd ) const;
  792.  
  793.       QCString mediaId( int mediaType ) const;
  794.  
  795.       QString m_vendor;
  796.       QString m_description;
  797.       QString m_version;
  798.       QString m_cdrdaoDriver;
  799.       int m_cdTextCapable;
  800.       int m_maxReadSpeed;
  801.       int m_maxWriteSpeed;
  802.       int m_currentWriteSpeed;
  803.  
  804.       bool m_dvdMinusTestwrite;
  805.  
  806.       // only needed for scsi devices
  807.       int m_bus;
  808.       int m_target;
  809.       int m_lun;
  810.  
  811.       int m_bufferSize;
  812.  
  813.       int m_writeModes;
  814.  
  815.       // only needed on FreeBSD
  816.       QString m_passDevice;
  817.       QString m_blockDevice;
  818.       QString m_genericDevice;
  819.  
  820.       class Private;
  821.       Private* d;
  822.       friend class DeviceManager;
  823.     };
  824.  
  825. #if defined(Q_OS_LINUX) || defined(Q_OS_NETBSD)
  826.   /**
  827.    * This should always be used to open a device since it
  828.    * uses the resmgr
  829.    *
  830.    * @internal
  831.    */
  832.   int openDevice( const char* name, bool write = false );
  833. #endif
  834. }
  835.  
  836. #endif
  837.